using DocumentCreationSystem.Models.AgentOps;

namespace DocumentCreationSystem.Services.AgentOps
{
    /// <summary>
    /// AgentOps工作流引擎接口 - 实现智能规划模板的自动执行和监控
    /// </summary>
    public interface IAgentOpsWorkflowEngine
    {
        /// <summary>
        /// 从智能规划模板创建工作流
        /// </summary>
        /// <param name="planningTemplate">智能规划模板</param>
        /// <returns>可执行的工作流实例</returns>
        Task<AgentWorkflow> CreateWorkflowFromTemplateAsync(PlanningTemplate planningTemplate);

        /// <summary>
        /// 执行工作流
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        /// <param name="executionContext">执行上下文</param>
        /// <param name="progressCallback">进度回调</param>
        /// <returns>执行结果</returns>
        Task<WorkflowExecutionResult> ExecuteWorkflowAsync(
            string workflowId, 
            WorkflowExecutionContext executionContext,
            IProgress<WorkflowProgress>? progressCallback = null);

        /// <summary>
        /// 暂停工作流执行
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        Task PauseWorkflowAsync(string workflowId);

        /// <summary>
        /// 恢复工作流执行
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        Task ResumeWorkflowAsync(string workflowId);

        /// <summary>
        /// 停止工作流执行
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        Task StopWorkflowAsync(string workflowId);

        /// <summary>
        /// 获取工作流状态
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        /// <returns>工作流状态</returns>
        Task<WorkflowStatusInfo> GetWorkflowStatusAsync(string workflowId);

        /// <summary>
        /// 获取工作流执行历史
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        /// <returns>执行历史</returns>
        Task<List<WorkflowExecutionHistory>> GetExecutionHistoryAsync(string workflowId);

        /// <summary>
        /// 获取工作流性能指标
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        /// <returns>性能指标</returns>
        Task<WorkflowMetrics> GetWorkflowMetricsAsync(string workflowId);

        /// <summary>
        /// 优化工作流
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        /// <param name="optimizationStrategy">优化策略</param>
        /// <returns>优化结果</returns>
        Task<WorkflowOptimizationResult> OptimizeWorkflowAsync(
            string workflowId, 
            WorkflowOptimizationStrategy optimizationStrategy);

        /// <summary>
        /// 获取所有活跃工作流
        /// </summary>
        /// <returns>活跃工作流列表</returns>
        Task<List<AgentWorkflow>> GetActiveWorkflowsAsync();

        /// <summary>
        /// 注册工作流事件监听器
        /// </summary>
        /// <param name="listener">事件监听器</param>
        void RegisterEventListener(IWorkflowEventListener listener);

        /// <summary>
        /// 移除工作流事件监听器
        /// </summary>
        /// <param name="listener">事件监听器</param>
        void RemoveEventListener(IWorkflowEventListener listener);
    }

    /// <summary>
    /// 工作流事件监听器接口
    /// </summary>
    public interface IWorkflowEventListener
    {
        /// <summary>
        /// 工作流状态变更事件
        /// </summary>
        Task OnWorkflowStatusChangedAsync(string workflowId, WorkflowStatus oldStatus, WorkflowStatus newStatus);

        /// <summary>
        /// 任务完成事件
        /// </summary>
        Task OnTaskCompletedAsync(string workflowId, string taskId, TaskExecutionResult result);

        /// <summary>
        /// 工作流错误事件
        /// </summary>
        Task OnWorkflowErrorAsync(string workflowId, WorkflowError error);

        /// <summary>
        /// 工作流完成事件
        /// </summary>
        Task OnWorkflowCompletedAsync(string workflowId, WorkflowExecutionResult result);
    }
}
